package com.hm.hall.commons.handler;

import com.hm.hall.commons.constans.ErrorCode;
import com.hm.hall.commons.domain.resp.BaseResponse;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalExceptionHandler {

    Logger log = Logger.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public BaseResponse jsonErrorHandler(HttpServletRequest req, Exception e) throws Exception {
        //打印日志 返回未知错误
        log.error("捕捉到错误", e);
        return new BaseResponse(ErrorCode.parament_error);
    }
}
